from flask import Flask
from flask import request
from ..entity.user import User
from ..service.user import user_list,user_add,user_update

def user_handle(app:Flask):
  @app.post("/get_user_list")
  def get_user_list():
    params=request.get_json()
    list,total=user_list(params['keyword'],params['page'],params['size'])
    return {
      "code":200,
      "msg":"",
      "data":{
      "list":[user.to_json() for user in list],
      "total":total
      }
    }
  @app.post("/add_user")
  def add_user():
    params=request.get_json()
    user=User()
    user.name=params['name']
    user.gender=params['gender']
    user_add(user)
    return {
      "code":200,
      "msg":"",
      "data":None,
    }
  @app.post("/edit_user")
  def edit_user():
    params=request.get_json()
    user=User()
    user.uid=params['uid']
    user.name=params['name']
    user.gender=params['gender']
    user_update(user)
    return {
      "code":200,
      "msg":"",
      "data":None,
    }